package com.shwread.address.tree_view;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shwread.address.bean.Node;
import com.shwread.android.qysw10000204.R;

import java.util.List;

import static android.util.TypedValue.COMPLEX_UNIT_SP;

public class SimpleTreeAdapter<T> extends TreeListViewAdapter<T> {
    public SimpleTreeAdapter(ListView mTree, Context context, List<T> datas, int defaultExpandLevel)
            throws IllegalArgumentException, IllegalAccessException {
        super(mTree, context, datas, defaultExpandLevel);
    }

    @Override
    public View getConvertView(Node node, int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.address_list_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.icon = (ImageView) convertView.findViewById(R.id.id_treenode_icon);
            viewHolder.label = (TextView) convertView.findViewById(R.id.id_treenode_label);
            viewHolder.list_item = (RelativeLayout) convertView.findViewById(R.id.address_list_item);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
//        if (node.getIcon() == -1) {
////            viewHolder.icon.setVisibility(View.INVISIBLE);
//            viewHolder.icon.setImageResource(R.drawable.more_right_bg);
//        } else {
            viewHolder.icon.setImageResource(node.getIcon());//设置箭头图标方向
//        }
        switch (node.getLevel()) {
            case 0://第一层
                viewHolder.label.setTextColor(0xFF000000);
                viewHolder.label.setTextSize(COMPLEX_UNIT_SP,16);
                viewHolder.list_item.setBackgroundColor(0xFFFFFFFF);
                break;
            case 1://第二层
                viewHolder.label.setTextColor(0xFF000000);
                viewHolder.label.setTextSize(COMPLEX_UNIT_SP,15);
                viewHolder.list_item.setBackgroundColor(0xFFF7F7F7);
                break;
            case 2://第三层
                viewHolder.label.setTextColor(0xFF666666);
                viewHolder.label.setTextSize(COMPLEX_UNIT_SP,14);
                viewHolder.list_item.setBackgroundColor(0xFFF1F1F1);
                break;
            case 3://第四层
                viewHolder.label.setTextColor(0xFF464646);
                viewHolder.label.setTextSize(COMPLEX_UNIT_SP,14);
                viewHolder.list_item.setBackgroundColor(0xFFEDEDED);
                break;
        }
        viewHolder.label.setText(node.getBean().getGroupName());//设置目录名
        return convertView;
    }

    private static class ViewHolder {
        ImageView icon;
        TextView label;
        RelativeLayout list_item;
    }
}
